package com.carbonfive.robopie;

import java.util.Iterator;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.ArcShape;
import android.graphics.drawable.shapes.OvalShape;
import android.graphics.drawable.shapes.Shape;
import android.view.View;

public class Pie extends View {
	private Slice[] slices;

	
	public Pie(Context context) {
		super(context);		
		slices = new Slice[5];
		for (int i = 0; i < slices.length; i++) {
			slices[i] = new Slice(new ArcShape(-60*i-90, 60));
		}
		
	}
	
	private static class Slice extends ShapeDrawable {
		private Paint mPaintStroke = new Paint(Paint.ANTI_ALIAS_FLAG);
		private boolean mFiled;

		public Slice(Shape s) {
			super(s);
			mPaintStroke.setStyle(Paint.Style.STROKE);
			mPaintStroke.setColor(0xFFEEFF00);			
			mPaintStroke.setStrokeWidth(5);
		}
		
		@Override
		protected void onDraw(Shape shape, Canvas canvas, Paint paint) {
			if (!mFiled) {
				paint.setColor(0xE95E2400);
				shape.draw(canvas, paint);
				shape.draw(canvas, mPaintStroke);
			} else {
				paint.setColor(0xFFEEFF00);
				shape.draw(canvas, paint);
			}
		}
		
		public void fill(Canvas canvas) {
			mFiled = true;
			draw(canvas);
		}
	}
	
	@Override
	protected void onDraw(Canvas canvas) {
		for (Slice slice : slices) {
			slice.setBounds(10, 10, 300, 300);
			slice.draw(canvas);
		}
		slices[4].fill(canvas);
	}
	
}